package com.kaifamiao.demo.d0729.pm;


public class Demo {

    public static void main(String[] args) {

        Person person = new Person();
        Student stu = new Student();

        Person person1 = new Student();
        person1.age = 18;
//        Student student = (Student) new Person(); // error
        /*
            call 方法需要 Person 类型的参数
         */
        call(new Person());
        call(new Student());
        call(new Teacher());
        call(new BoyStudent());

        // 重写，同名同参同(同类型)返回
    }

    public static void call(Person person){
        // 父类中定义的方法，子类会继承
        person.say();

        // 向下转型
        if (person instanceof Student student){
//            Student student = (Student) person;
            student.name = " 张三 ";
            student.study();
        }
    }

    public static Person call2(){
        return new Student();
//        return new Teacher();
//        return new Person();
    }
}
